#include<bits/stdc++.h>
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x);write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=1e6+5,mod=998244353,INV2=(mod+1)/2,INV6=(mod+1)/6;
inline int Mod(int x){return x>=mod?x-mod:x;}
int n;
int a[N];
void Init(){
	read(n);
	deque<int>q;
	for(int i=1;i<=n;i++){
		int x;
		read(x);
		q.push_back(x);	
	}
	while(q.back()!=0){
		q.push_back(q.front());
		q.pop_front();
	}
	for(int i=1;i<=n;i++){
		a[i]=q.front();
		q.pop_front();
	}
}
void sol(){
	int sum1=1ll*a[1]*(a[1]+1)%mod*INV2%mod;
	int sum2=Mod(1ll*a[1]*a[1]%mod*(a[1]+1)%mod*INV2%mod+mod-1ll*a[1]*(a[1]+1)%mod*Mod(a[1]+a[1]+1)%mod*INV6%mod); 
	for(int i=2;i<n;i++){
		int now1=Mod(Mod(1ll*a[i]*(a[i]+1)%mod*sum1%mod+1ll*(a[i]+1)*sum2%mod)+mod-1ll*a[i]*(a[i]+1)%mod*INV2%mod*sum1%mod);
		int now2=Mod(Mod(1ll*a[i]*a[i]%mod*(a[i]+1)%mod*INV2%mod*sum1%mod+1ll*a[i]*(a[i]+1)%mod*INV2%mod*sum2%mod)+mod-1ll*a[i]*(a[i]+1)%mod*Mod(2*a[i]+1)%mod*INV6%mod*sum1%mod);
		sum1=now1,sum2=now2;
	}
	write(sum2);
}
int main(){
	freopen("trade.in","r",stdin);
	freopen("trade.out","w",stdout);
	Init();
	sol();
	flush();
	return 0;
}

